package cn.com.headfree.mouldshow.controller;


//import cn.com.headfree.base.controller.ExBaseController;

import cn.com.headfree.mouldshow.service.*;
import cn.com.headfree.util.ExcelExportUtil;
import cn.com.headfree.util.PerInfoUtil;
import cn.com.headfree.util.SysDictionaryUtil;
import cn.com.headfree.vo.SysDictionaryInfoVo;
import cn.com.headfree.vo.simple.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 导出excel
 */
@CrossOrigin("*")
@RestController
@RequestMapping(value = "/exportExcel", produces = "application/json;charset=UTF-8")
public class ExportExcelController {

    //    private static final Logger log = Logger.getLogger(ExportExcelController.class);
    private static final Logger log = LogManager.getLogger(ExportExcelController.class);

    //个人基本信息
    @Value("${empBaseInfo}")
    private String empBaseInfo;
    //竞赛考试信息
    @Value("${contestInfo}")
    private String contestInfo;

    //学术成果
    @Value("${acadeAchiveInfo}")
    private String acadeAchiveInfo;

    //继续教育培训经理授课经历
    @Value("${contiStudyInfo}")
    private String contiStudyInfo;

    //学历信息表
    @Value("${educateInfo}")
    private String educateInfo;

    //专家人才称号信息
    @Value("${expertTitleInfo}")
    private String expertTitleInfo;

    //个人荣誉信息
    @Value("${honorInfo}")
    private String honorInfo;

    //专利信息
    @Value("${patentInfo}")
    private String patentInfo;

    //专业技术资格信息
    @Value("${proTecInfo}")
    private String proTecInfo;

    //项目课程成果
    @Value("${projAchieveInfo}")
    private String projAchieveInfo;

    //项目课题获得奖励信息
    @Value("${projAwardInfo}")
    private String projAwardInfo;

    //徒弟获得奖励信息
    @Value("${stdAward}")
    private String stdAward;

    //师带徒徒弟信息
    @Value("${sdtPrentInfo}")
    private String sdtPrentInfo;

    //导师带徒
    @Value("${sdtTutorPrentInfo}")
    private String sdtTutorPrentInfo;

    //技能等级信息
    @Value("${skillLevelInfo}")
    private String skillLevelInfo;

    //制度标准
    @Value("${standInfo}")
    private String standInfo;

    //技艺革新信息
    @Value("${tecInnovInfo}")
    private String tecInnovInfo;

    //科技及管理创新成果
    @Value("${tecManInnov}")
    private String tecManInnov;

    //工作经历信息
    @Value("${workExpInfo}")
    private String workExpInfo;

    //年度绩效信息
    @Value("${yearEffectInfo}")
    private String yearEffectInfo;

    @Resource
    private TEmpBaseInfoService tEmpBaseInfoService;

    @Resource
    private TEducateInfoService tEducateInfoService;

    @Resource
    private TContestInfoService tContestInfoService;

    @Resource
    private TAcadeAchiveInfoService tAcadeAchiveInfoService;

    @Resource
    private TContiStudyInfoService tContiStudyInfoService;

    @Resource
    private TExpertTitleInfoService tExpertTitleInfoService;

    @Resource
    private THonorInfoService tHonorInfoService;

    @Resource
    private TPatentInfoService tPatentInfoService;

    @Resource
    private TProTecInfoService tProTecInfoService;

    @Resource
    private TProjAchieveInfoService tProjAchieveInfoService;

    @Resource
    private TSdtTutorPrentInfoService tSdtTutorPrentInfoService;

    @Resource
    private TSkillLevelInfoService tSkillLevelInfoService;

    @Resource
    private TStandInfoService tStandInfoService;

    @Resource
    private TTecInnovInfoService tTecInnovInfoService;

    @Resource
    private TTecManInnovService tTecManInnovService;

    @Resource
    private TWorkExpInfoService tWorkExpInfoService;

    @Resource
    private TYearEffectInfoService tYearEffectInfoService;

    @Resource
    private HumanDataService humanDataService;
//    private humanDataService humanDataService;

    /**
     * 导出部门中人员的信息到excel
     *
     * @param request
     * @param response
     * @param deptId
     * @return
     */
    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, String deptId, String filename) {
        try {
            if (StringUtils.isBlank(deptId) || StringUtils.isBlank(filename)) {
                log.error("人资管理按部门导出部门下人员信息异常:部门id[baseorgId]和文件名[fileName]不能为空!!!");
                return;
            }

            log.info("从redis中获取字典数据");
            Map<String, List<SysDictionaryInfoVo>> map = SysDictionaryUtil.getSysDictionaryList();

            log.info("export excel:select the list info.");
            //查询人员基本信息
            //List<EmpBaseInfoVo> empBaseInfos = tEmpBaseInfoService.findByBaseorgId(deptId);
            List<EmpBaseInfoVo> empBaseInfos = humanDataService.getTEmpBaseInfoPageList("",deptId);
            for (EmpBaseInfoVo vo : empBaseInfos) {
                vo.setSex(getNameByValue("Gender", vo.getSex(),map));
                vo.setNation(getNameByValue("Nation", vo.getNation(),map));
                vo.setPolitiStatus(getNameByValue("PoliticalLandscapeText",vo.getPolitiStatus(),map));
            }
//            log.info("export excel:EmpBaseInfoVo");
            //竞赛考试信息
            //List<ContestInfoVo> contestInfos = tContestInfoService.findByBaseorgId(deptId);
            List<ContestInfoVo> contestInfos = humanDataService.getTContestInfoPageList("",deptId);

            for (ContestInfoVo vo : contestInfos) {
                vo.setAwardLevel(getNameByValue("JygexinQcJb",vo.getAwardLevel(),map));
                vo.setCompRank(getNameByValue("JygexinQcDj",vo.getCompRank(),map));
            }

//            log.info("export excel:contestInfos");
            //学术成果
            //List<AcadeAchiveInfoVo> acadeAchiveInfos = tAcadeAchiveInfoService.findByBaseorgId(deptId);
            List<AcadeAchiveInfoVo> acadeAchiveInfos = humanDataService.getTAcadeAchiveInfoPageList("",deptId);

            for (AcadeAchiveInfoVo vo : acadeAchiveInfos) {
                vo.setAcadType(getNameByValue("XueshuchengguoType",vo.getAcadType(),map));
                vo.setLevel(getNameByValue("XueshuchengguoJb",vo.getLevel(),map));
                vo.setRole(getNameByValue("XueshuchengguoJs",vo.getRole(),map));
            }

//            log.info("export excel:AcadeAchiveInfoVo");
            //培训经历和授课经历
            //List<ContiStudyInfoVo> contiStudyInfos = tContiStudyInfoService.findByBaseorgId(deptId);
            List<ContiStudyInfoVo> contiStudyInfos = humanDataService.getTContiStudyInfoPageList("",deptId);

            for (ContiStudyInfoVo vo : contiStudyInfos) {
                vo.setType(getNameByValue("PeixunshoukeType",vo.getType(),map));
            }

//            log.info("export excel:ContiStudyInfoVo");

            //查询人员学历信息
            //List<EducateInfoVo> educateInfos = tEducateInfoService.findByBaseorgId(deptId);
            List<EducateInfoVo> educateInfos = humanDataService.getTEducateInfoPageList("",deptId);

            for (EducateInfoVo vo : educateInfos) {
                vo.setSchoolType(getNameByValue("CollegeCategory",vo.getSchoolType(),map));
                vo.setEducName(getNameByValue("PersonnelQualifications",vo.getEducName(),map));
                vo.setDegreeName(getNameByValue("AcademicDegree",vo.getDegreeName(),map));
            }

//            log.info("export excel:EducateInfoVo");
            //专家人才称号信息
            //List<ExpertTitleInfoVo> expertTitleInfos = tExpertTitleInfoService.findByBaseorgId(deptId);
            List<ExpertTitleInfoVo> expertTitleInfos = humanDataService.getTExpertTitleInfoPageList("",deptId);

            for (ExpertTitleInfoVo vo : expertTitleInfos) {
                vo.setEmpTitle(getNameByValue("TalentTitle",vo.getEmpTitle(),map));
                vo.setMajor(getNameByValue("ProWorkTypes",vo.getMajor(),map));
                vo.setType(getNameByValue("ExpertCategory",vo.getType(),map));
                vo.setLevelName(getNameByValue("ExpertLevel",vo.getLevelName(),map));
            }

//            log.info("export excel:ExpertTitleInfoVo");
            //个人荣誉
            //List<HonorInfoVo> honorInfos = tHonorInfoService.findByBaseorgId(deptId);
            List<HonorInfoVo> honorInfos = humanDataService.getTHonorInfoPageList("",deptId);

            for (HonorInfoVo vo : honorInfos) {
                vo.setHonorLevel(getNameByValue("JygexinQcJb",vo.getHonorLevel(),map));
                vo.setHonorType(getNameByValue("RuYuLeiBie",vo.getHonorType(),map));
            }

//            log.info("export excel:HonorInfoVo");
            //专利信息
            //List<PatentInfoVo> patentInfoVos = tPatentInfoService.findByBaseorgId(deptId);
            List<PatentInfoVo> patentInfoVos = humanDataService.getTPatentInfoPageList("",deptId);

            for (PatentInfoVo vo : patentInfoVos) {
                vo.setPatentType(getNameByValue("PatentType",vo.getPatentType(),map));
            }

//            log.info("export excel:PatentInfoVo");
            //专业技术资格信息
            //List<ProTecInfoVo> proTecInfoVos = tProTecInfoService.findByBaseorgId(deptId);
            List<ProTecInfoVo> proTecInfoVos = humanDataService.getTProTecInfoPageList("",deptId);

            for (ProTecInfoVo vo : proTecInfoVos) {
                vo.setSubjSet(getNameByValue("ProTechnicalQualifications",vo.getSubjSet(),map));
                vo.setSubjLevel(getNameByValue("ProfessionalQualifications",vo.getSubjLevel(),map));
                vo.setOrgLevel(getNameByValue("IdentificationUnitLevel",vo.getOrgLevel(),map));
            }

//            log.info("export excel:ProTecInfoVo");
            //项目课程成果
            //List<ProjAchieveInfoVo> projAchieveInfoVos = tProjAchieveInfoService.findByBaseorgId(deptId);
            List<ProjAchieveInfoVo> projAchieveInfoVos = humanDataService.getTProjAchieveInfoPageList("",deptId);

            for (ProjAchieveInfoVo vo : projAchieveInfoVos) {
                vo.setProjLevel(getNameByValue("StandardLevel",vo.getProjLevel(),map));
                vo.setRole(getNameByValue("XiangMuKeTiJS",vo.getRole(),map));
            }

//            log.info("export excel:ProjAchieveInfoVo");
            //导师带徒
            //List<SdtTutorPrentInfoVo> sdtTutorPrentInfoVos = tSdtTutorPrentInfoService.findByBaseorgId(deptId);
            List<SdtTutorPrentInfoVo> sdtTutorPrentInfoVos = humanDataService.getTSdtTutorPrentInfoPageList("",deptId);

//            log.info("export excel:SdtTutorPrentInfoVo");
            //技能等级信息
            //List<SkillLevelInfoVo> skillLevelInfoVos = tSkillLevelInfoService.findByBaseorgId(deptId);
            List<SkillLevelInfoVo> skillLevelInfoVos = humanDataService.getTSkillLevelInfoPageList("",deptId);

            for (SkillLevelInfoVo vo : skillLevelInfoVos) {
                vo.setTechType(getNameByValue("SkillAppraisalWork",vo.getTechType(),map));
                vo.setQualifiLevel(getNameByValue("QualificationLevel",vo.getQualifiLevel(),map));
                vo.setOrgLevel(getNameByValue("IdentificationUnitLevel",vo.getOrgLevel(),map));
            }

//            log.info("export excel:SkillLevelInfoVo");
            //标准制定
            //List<StandInfoVo> standInfoVos = tStandInfoService.findByBaseorgId(deptId);
            List<StandInfoVo> standInfoVos = humanDataService.getTStandInfoPageList("",deptId);

            for (StandInfoVo vo : standInfoVos) {
                vo.setType(getNameByValue("ZdbzType",vo.getType(),map));
                vo.setLevel(getNameByValue("JygexinQcJb",vo.getLevel(),map));
                vo.setRole(getNameByValue("XueshuchengguoJs",vo.getRole(),map));
            }

//            log.info("export excel:StandInfoVo");
            //技艺革新信息
            //List<TecInnovInfoVo> tecInnovInfoVos = tTecInnovInfoService.findByBaseorgId(deptId);
            List<TecInnovInfoVo> tecInnovInfoVos = humanDataService.getTTecInnovInfoPageList("",deptId);

            for (TecInnovInfoVo vo : tecInnovInfoVos) {
                vo.setAwardLevel(getNameByValue("JygexinQcJb",vo.getAwardLevel(),map));
                vo.setAwardGrade(getNameByValue("JygexinQcDj",vo.getAwardGrade(),map));
            }

//            log.info("export excel:TecInnovInfoVo");
            //科技及管理创新成果
            //List<TecManInnovVo> tecManInnovVos = tTecManInnovService.findByBaseorgId(deptId);
            List<TecManInnovVo> tecManInnovVos = humanDataService.getTTecManInnovPageList("",deptId);

            for (TecManInnovVo vo : tecManInnovVos) {
                vo.setAchiType(getNameByValue("KjglAchiveType",vo.getAchiType(),map));
                vo.setAwardLevel(getNameByValue("JygexinQcJb",vo.getAwardLevel(),map));
                vo.setAwardGrade(getNameByValue("JygexinQcDj",vo.getAwardGrade(),map));
            }

//            log.info("export excel:TecManInnovVo");
            //工作经历
            //List<WorkExpInfoVo> workExpInfoVos = tWorkExpInfoService.findByBaseorgId(deptId);
            List<WorkExpInfoVo> workExpInfoVos = humanDataService.getTWorkExpInfoPageList("",deptId);

            for (WorkExpInfoVo vo : workExpInfoVos) {
                vo.setRank(getNameByValue("DutyLevel",vo.getRank(),map));
                vo.setPostType(getNameByValue("PostCategory",vo.getPostType(),map));
            }

//            log.info("export excel:WorkExpInfoVo");
            //List<YearEffectInfoVo> yearEffectInfoVos = tYearEffectInfoService.findByBaseorgId(deptId);
            List<YearEffectInfoVo> yearEffectInfoVos = humanDataService.getTYearEffectInfoPageList("",deptId);

            for (YearEffectInfoVo vo : yearEffectInfoVos) {
                vo.setPerforGrade(getNameByValue("PerformLevelRecentThreeYears",vo.getPerforGrade(),map));
            }


//            log.info("export excel:YearEffectInfoVo");
            log.info("export info:deal with result for titles.");
            //导出数据处理
            //获取标题
            String[] empBaseInfoTitles = empBaseInfo.split(",");
            String[] contestInfoTitles = contestInfo.split(",");
            String[] acadeAchiveTitles = acadeAchiveInfo.split(",");
            String[] contiStudyInfoTitles = contiStudyInfo.split(",");

            String[] educateInfoTitles = educateInfo.split(",");
            String[] expertTitleInfoTitles = expertTitleInfo.split(",");
            String[] honorInfoTitles = honorInfo.split(",");
            String[] patentInfoTitles = patentInfo.split(",");
            String[] proTecInfoTitles = proTecInfo.split(",");
            String[] projAchieveInfoTitles = projAchieveInfo.split(",");//成果信息须要再次关联t_proj_award_info
            String[] sdtTutorPrentInfoTitles = sdtTutorPrentInfo.split(",");
            String[] skillLevelInfoTitles = skillLevelInfo.split(",");
            String[] standInfoTitles = standInfo.split(",");
            String[] tecInnovInfoTitles = tecInnovInfo.split(",");
            String[] tecManInnovTitles = tecManInnov.split(",");
            String[] workExpInfoTitles = workExpInfo.split(",");
            String[] yearEffectInfoTitles = yearEffectInfo.split(",");
            log.info("export excel:deal with the result for content.");

            //获取数据
            String[][] empBaseInfoContent = PerInfoUtil.zhEmpBaseInfo(empBaseInfos, empBaseInfoTitles);
//            log.info("export excel content:empBaseInfoContent");
            String[][] contestInfoContent = PerInfoUtil.zhContestInfo(contestInfos, contestInfoTitles);
//            log.info("export excel content:contestInfoContent");
            String[][] acadeAchiveContent = PerInfoUtil.zhAcadeAchiveInfo(acadeAchiveInfos, acadeAchiveTitles);
//            log.info("export excel content:acadeAchiveContent");
            String[][] contiStudyInfoContent = PerInfoUtil.zhContiStudyInfo(contiStudyInfos, contiStudyInfoTitles);
//            log.info("export excel content:contiStudyInfoContent");

            String[][] educateInfoContent = PerInfoUtil.zhEducateInfo(educateInfos, educateInfoTitles);
//            log.info("export excel content:educateInfoContent");
            String[][] expertTitleInfoContent = PerInfoUtil.zhExpertTitleInfo(expertTitleInfos, expertTitleInfoTitles);
//            log.info("export excel content:expertTitleInfoContent");
            String[][] honorInfoContent = PerInfoUtil.zhHonorInfo(honorInfos, honorInfoTitles);
//            log.info("export excel content:honorInfoContent");
            String[][] patentInfoContent = PerInfoUtil.zhPatentInfo(patentInfoVos, patentInfoTitles);
//            log.info("export excel content:patentInfoContent");
            String[][] proTecInfoContent = PerInfoUtil.zhProTecInfo(proTecInfoVos, proTecInfoTitles);
//            log.info("export excel content:proTecInfoContent");
            String[][] projAchieveInfoContent = PerInfoUtil.zhProjAchieveInfo(projAchieveInfoVos, projAchieveInfoTitles);
//            log.info("export excel content:projAchieveInfoContent");
            String[][] sdtTutorPrentInfoContent = PerInfoUtil.zhSdtTutorPrentInfo(sdtTutorPrentInfoVos, sdtTutorPrentInfoTitles);
//            log.info("export excel content:sdtTutorPrentInfoContent");
            String[][] skillLevelInfoContent = PerInfoUtil.zhSkillLevelInfo(skillLevelInfoVos, skillLevelInfoTitles);
//            log.info("export excel content:skillLevelInfoContent");
            String[][] standInfoContent = PerInfoUtil.zhStandInfo(standInfoVos, standInfoTitles);
//            log.info("export excel content:standInfoContent");
            String[][] tecInnovInfoContent = PerInfoUtil.zhTecInnovInfo(tecInnovInfoVos, tecInnovInfoTitles);
//            log.info("export excel content:tecInnovInfoContent");
            String[][] tecManInnovContent = PerInfoUtil.zhTecManInnov(tecManInnovVos, tecManInnovTitles);
//            log.info("export excel content:tecManInnovContent");
            String[][] workExpInfoContent = PerInfoUtil.zhWorkExpInfo(workExpInfoVos, workExpInfoTitles);
//            log.info("export excel content:workExpInfoContent");
            String[][] yearEffectInfoContent = PerInfoUtil.zhYearEffectInfo(yearEffectInfoVos, yearEffectInfoTitles);
//            log.info("export excel content:yearEffectInfoContent");

            //sheet名称
            String empBaseInfoSheetName = "人员基本信息";
            String contestInfoSheetName = "竞赛考试信息";
            String acadeAchiveSheetName = "学术成果";
            String contiStudyInfoSheetName = "教育培训及授课经历";

            String educateInfoSheetName = "学历信息";
            String expertTitleInfoSheetName = "专家人才称号";
            String honorInfoSheetName = "个人荣誉";
            String patentInfoSheetName = "专利、软件著作权";
            String proTecInfoSheetName = "专业技术资格";
            String projAchieveInfoSheetName = "项目课题成果";
            String sdtTutorPrentInfoSheetName = "导师带徒";
            String skillLevelInfoSheetName = "技能等级信息";
            String standInfoSheetName = "制度标准";
            String tecInnovInfoSheetName = "技艺革新信息";
            String tecManInnovSheetName = "科技及管理、创新成果";
            String workExpInfoSheetName = "工作经历";
            String yearEffectInfoSheetName = "年度绩效";

            log.info("export excel:product workspace.");
            //创建workbook
            XSSFWorkbook workbook = new XSSFWorkbook();

            workbook = ExcelExportUtil.exportExcel(workbook, empBaseInfoTitles, empBaseInfoContent, empBaseInfoSheetName,1);//基本信息
            workbook = ExcelExportUtil.exportExcel(workbook, educateInfoTitles, educateInfoContent, educateInfoSheetName,2);//学历信息
            workbook = ExcelExportUtil.exportExcel(workbook, workExpInfoTitles, workExpInfoContent, workExpInfoSheetName,3);//工作经历
            workbook = ExcelExportUtil.exportExcel(workbook, contiStudyInfoTitles, contiStudyInfoContent, contiStudyInfoSheetName,4);//教育培训及授课经历
            workbook = ExcelExportUtil.exportExcel(workbook, honorInfoTitles, honorInfoContent, honorInfoSheetName,5);//个人荣誉
            workbook = ExcelExportUtil.exportExcel(workbook, contestInfoTitles, contestInfoContent, contestInfoSheetName,6);//竞赛考试
            workbook = ExcelExportUtil.exportExcel(workbook, expertTitleInfoTitles, expertTitleInfoContent, expertTitleInfoSheetName,7);//专家人才称号
            workbook = ExcelExportUtil.exportExcel(workbook, proTecInfoTitles, proTecInfoContent, proTecInfoSheetName,8);//专业技术资格
            workbook = ExcelExportUtil.exportExcel(workbook, skillLevelInfoTitles, skillLevelInfoContent, skillLevelInfoSheetName,9);//技术等级
            workbook = ExcelExportUtil.exportExcel(workbook, sdtTutorPrentInfoTitles, sdtTutorPrentInfoContent, sdtTutorPrentInfoSheetName,10);//导师带徒
            workbook = ExcelExportUtil.exportExcel(workbook, yearEffectInfoTitles, yearEffectInfoContent, yearEffectInfoSheetName,11);//年度绩效
            workbook = ExcelExportUtil.exportExcel(workbook, acadeAchiveTitles, acadeAchiveContent, acadeAchiveSheetName,12);//学术成果
            workbook = ExcelExportUtil.exportExcel(workbook, standInfoTitles, standInfoContent, standInfoSheetName,13);//标准制定
            workbook = ExcelExportUtil.exportExcel(workbook, patentInfoTitles, patentInfoContent, patentInfoSheetName,14);//专利
            workbook = ExcelExportUtil.exportExcel(workbook, tecInnovInfoTitles, tecInnovInfoContent, tecInnovInfoSheetName,15);//技艺革新
            workbook = ExcelExportUtil.exportExcel(workbook, tecManInnovTitles, tecManInnovContent, tecManInnovSheetName,16);//科技创新
            workbook = ExcelExportUtil.exportExcel(workbook, projAchieveInfoTitles, projAchieveInfoContent, projAchieveInfoSheetName,17);//项目课题成果

            //响应生成excel
//            String fileName = "人员信息";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");

            log.info("export excel:start return to broswer.");
            exportExcel2Browser(request, response, filename + sdf.format(new Date()), workbook);

            log.info("导出excel成功");
        } catch (Exception e) {
            log.error("导出excel失败!!!", e);
        }
    }

    /**
     * 向页面导出excel
     *
     * @param request
     * @param response
     * @param fileName 文件名称
     * @param workbook 工作簿
     */
    private void exportExcel2Browser(HttpServletRequest request, HttpServletResponse response, String fileName, XSSFWorkbook workbook) {
        OutputStream os = null;
        try {
            ExcelExportUtil.setResponseHeader(request, response, fileName);
            os = response.getOutputStream();
            workbook.write(os);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.flush();
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 获取name值
     *
     * @param name
     * @param dictValue
     * @return
     */
    public static String getNameByValue(String name, String dictValue,Map<String, List<SysDictionaryInfoVo>> map) {
        List<SysDictionaryInfoVo> entityList = map.get(name);
        String dictName = "";
        if (dictValue != null) {
            if (entityList != null && entityList.size() > 0) {
                for (int i = 0; i < entityList.size(); i++) {
                    SysDictionaryInfoVo entity = JSONObject.parseObject(JSON.toJSONString(entityList.get(i)), SysDictionaryInfoVo.class);
                    if (dictValue.equals(entity.getValue())) {
                        dictName = entity.getName();
                        return dictName;
                    }
                }
            }
        }
//        return null;
//        return "";
        return dictValue;
    }
}
